define(
	[
		'require',
		'apm/form_upload',
		'apm/ui/myself_select/select'
	],
	function(require) {
		function cellFormatter(args, colume) {
			if (args.row.type & $.wijmo.wijgrid.rowType.data) {

				var ctrl = this.get("controller");
				var date = args.row.data.srcIP;

				var cb = $("<div class='date-text line'></div>").text(date);
				cb.dblclick(function() {
					ctrl.transitionToRoute("service.server.nodeserver", "app" + args.row.data.code);
				});
				cb.appendTo(args.$container);
				return true;
			}
		}

		var FormUploader = require('apm/form_upload');

		var Controller = Ember.Controller.extend({
			select: require('apm/ui/myself_select/select'),
			keyUpEnent: function(){
				var ctrl = this;
				setTimeout(function(){
					$("#mouseKeyUp1,#mouseKeyUp2").on("keyup",function(event){
						if(event.keyCode == 13){
							ctrl.followResponse();
						};
					});
				},0)
			},
			serviceValueChange: Ember.observer("serviceValue", function() {
				this.followResponse();
			}),
			pageSize: 10,
			needs: ["serviceServer"],

			modifyNnameRequest: function(serviceId, params) {
				return this.store.ajax("PUT", "nodes/" + serviceId + "/serviceName", params);
			},
			initTime: function(){
		        var ctrl = this;

		        var sdate = new Date(new Date() - timeD_value - 60000-60000);
		        sdate.setSeconds(0);
		        sdate.setMilliseconds(0); 
		        ctrl.set("startDate",new Date(+sdate));

		        var edate = new Date(new Date() - timeD_value-60000);
		        edate.setSeconds(0);
		        edate.setMilliseconds(0); 
		        ctrl.set("endDate",new Date(+edate));
		    },

			dialogButtons: {
				ok: {
					text: "确定",
					"class": "btn btn-primary",
					click: function() {
						var ctrl = this.get("controller");
						ctrl.send(ctrl.get('dialogAction') || "setLua", this);
					}
				},
				cancel: {
					text: "取消",
					"class": "btn",
					click: function() {
						var ctrl = this.get("controller");
						this.closeDialog();
						ctrl.set("setupGroupLua", false);
					}
				}
			},

			serviceType: Ember.A([]),

			getserviceType: function() {
				var me = this;
				return this.store.ajax("GET", "protocols/L7").then(function(response) {
					if (response.protocols) {
						var arr = [];
						Ember.EnumerableUtils.forEach(response.protocols, function(item) {
							arr.push({
								displaytext: item.name,
								value: item.l7_proto,
								data: item
							})
						});
						me.set("serviceType", Ember.A(arr));
					}
				});
			},

			clearserverity: function() {
				this.set("serverity", undefined);
			},
			serverColumns: Ember.computed(function() {
				var columns = [{
					headerText: "",
					dataKey: "id",
					width: 45,
					allowSort: false,
					selectAll: true,
					ensurePxWidth: true,
					cellFormatter: function(args, colume) {
						if (args.row.type & $.wijmo.wijgrid.rowType.data) {
							var ctrl = this.get("controller");
							var data = args.row.data;
							var cb = $("<input type='checkbox' class='grid-checkbox'/>");

							cb.prop("checked", data._checked)
								.appendTo(args.$container)
								.data("model", data);

							data._$checkbox = cb;
							data.ctrl = ctrl;
							args.$container
								.on("click", ":checkbox", ctrl.networkCheckboxClick);
							//将数据的_checked属性与checkbox的选中状态绑定
							Ember.addObserver(data, "_checked", ctrl.bindNetworkCheckedToCheckbox);
							return true;
						}
					}
				}, {
					headerText: "服务名",
					dataKey: "name",
					allowSort: false,
					cellFormatter: function(args, colume) {
						if (args.row.type & $.wijmo.wijgrid.rowType.data) {
							var ctrl = this.get("controller");
							var date = args.row.data.name;
							var severity = args.row.data.perfState.severity;
							if (!ctrl.get("auth.isNormal")) {
								var ModifyName = $("<i class='iconfont icon-wcunchu'></i>");
							};

							var text = $("<i class='btn-link modify-name-style'>" + date + "</i>");
							var cb = $("<div class='date-text pos of-hd'><i class='icon_alerts'></i></div>");
							text.appendTo(cb);
							if (severity) {
								switch (severity) {
									case 50:
										cb.find(".icon_alerts").addClass("icon_serious_alerts");
										break;
									case 20:
										cb.find(".icon_alerts").addClass("icon_remind_alerts");
										break;
									case 10:
										cb.find(".icon_alerts").addClass("icon_good_alerts");
										break;
								}
							}
							if (!ctrl.get("auth.isNormal")) {
								ModifyName.appendTo(cb);

								ModifyName.click(function() {
									var dialog = Broada.getView("serviceAllServer");
									ctrl.set("serviceNameformTip", "");
									ctrl.set("serviceInputName", date);
									ctrl.set('dialogAction', "setNodeName");
									ctrl.set("currentServiceId", args.row.data.id);
									ctrl.set("currentServiceObject", {
										"ip": args.row.data.ip,
										"port": args.row.data.port
									});
									dialog.openDialog();
								});
							}

							text.click(function() {
								ctrl.transitionToRoute("service.server.nodeserver", args.row.data);
							});
							cb.appendTo(args.$container);
							return true;
						}
					}

				}, {
					headerText: "IP地址",
					dataKey: "ip",
					allowSort: true,
					cellFormatter: function(args, colume) {
						if (args.row.type & $.wijmo.wijgrid.rowType.data) {

							var ctrl = this.get("controller");
							var date = args.row.data.ip;

							var cb = $("<div class='date-text line'></div>").text(date);
							cb.appendTo(args.$container);
							return true;
						}
					}
				}, {
					headerText: "端口",
					dataKey: "port",
					allowSort: true,
					cellFormatter: function(args, colume) {
						if (args.row.type & $.wijmo.wijgrid.rowType.data) {
							var ctrl = this.get("controller");
							var date = args.row.data.port;
							var cb = $("<div class='date-text line'></div>").text(date);

							cb.appendTo(args.$container);
							return true;
						}
					}
				}, {
					headerText: "服务类型",
					dataKey: "protocolName",
					allowSort: true,
					cellFormatter: function(args, colume) {
						if (args.row.type & $.wijmo.wijgrid.rowType.data) {
							var ctrl = this.get("controller");
							var data = args.row.data.protocolName;
							if (!data) {
								data = '-';
							}
							var cb = $("<div class='date-text line'></div>").text(data);
							cb.appendTo(args.$container);
							return true;
						}
					}
				}, {
					headerText: "吞吐量",
					dataKey: "throughput",
					allowSort: true,
					cellFormatter: function(args, colume) {
						if (args.row.type & $.wijmo.wijgrid.rowType.data) {
							var ctrl = this.get("controller"),
								data = args.row.data.throughput;
							if (data == 0) {
								data = 0;
							} else if (!data) {
								data = '-';
							}
							var cb = $("<div class='date-text icon_server_arrow_padding'>" + data + "<i ></i></div>");

							if (args.row.data.perfState) {

								var errorState = args.row.data.perfState.throughput;
								switch (errorState) {
									case 0:
										cb.removeClass("icon_server_arrow_padding");
										break;
									case 1:
										cb.find("i")[0].className = "icon_alerts icon_red_up";
										break;
									case 2:
										cb.find("i")[0].className = "icon_alerts icon_green_up";
										break;
									default:
										cb.removeClass("icon_server_arrow_padding");
										break;
								}
							}
							cb.appendTo(args.$container);
							return true;
						}
					}
				}, {
					headerText: "平均响应时间",
					dataKey: "response",
					allowSort: true,
					cellFormatter: function(args, colume) {
						if (args.row.type & $.wijmo.wijgrid.rowType.data) {
							var ctrl = this.get("controller"),
								data = args.row.data.response;
							data = APM.util.indicatorFormatter("transform_time")(data);
							if (data == 0) {
								data = 0;
							} else if (!data) {
								data = '-';
							}

							var cb = $("<div class='date-text icon_server_arrow_padding'>" + data + "<i></i></div>");

							if (args.row.data.perfState) {
								var errorState = args.row.data.perfState.responseTime;
								switch (errorState) {
									case 0:
										cb.removeClass("icon_server_arrow_padding");
										break;
									case 1:
										cb.find("i")[0].className = "icon_alerts icon_red_up";
										break;
									case 2:
										cb.find("i")[0].className = "icon_alerts icon_green_up";
										break;
									default:
										cb.removeClass("icon_server_arrow_padding");
										break;
								}
							}

							cb.appendTo(args.$container);
							return true;
						}
					}
				}, {
					headerText: "错误",
					dataKey: "error",
					allowSort: true,
					cellFormatter: function(args, colume) {
						if (args.row.type & $.wijmo.wijgrid.rowType.data) {
							var ctrl = this.get("controller"),
								data = args.row.data.errorNum;
							if (data == 0) {
								data = 0;
							} else if (!data) {
								data = '-';
							}

							var cb = $("<div class='date-text icon_server_arrow_padding'>" + data + "<i></i></div>");

							if (args.row.data.perfState) {
								var errorState = args.row.data.perfState.error;
								switch (errorState) {
									case 0:
										cb.removeClass("icon_server_arrow_padding");
										break;
									case 1:
										cb.find("i")[0].className = "icon_alerts icon_red_up";
										break;
									case 2:
										cb.find("i")[0].className = "icon_alerts icon_green_up";
										break;
									default:
										cb.removeClass("icon_server_arrow_padding");
										break;
								}
							}

							cb.appendTo(args.$container);
							return true;
						}
					}
				}, {
					headerText: "最后更新",
					dataKey: "timestamp",
					allowSort: true,
					cellFormatter: function(args, colume) {
						if (args.row.type & $.wijmo.wijgrid.rowType.data) {
							var ctrl = this.get("controller");
							var date = new Date(args.row.data.timestamp);
							var dateFor = APM.util.formatDate(date, "yyyy-MM-dd H:mm:ss");
							if (!(args.row.data.timestamp)) {
								dateFor = '-';
							}
							var cb = $("<div class='date-text line'></div>").text(dateFor);

							cb.appendTo(args.$container);
							return true;
						}
					}
				}];

				if (!this.get("auth.isNormal")) {
					if (!(this.get("auth.user").role == 1)) {
						columns.push({
							headerText: "操作",
							dataKey: "operation",
							allowSort: false,
							ensurePxWidth: true,
							cellFormatter: function(args, colume) {
								if (args.row.type & $.wijmo.wijgrid.rowType.data) {
									var ctrl = this.get("controller");
									var date = args.row.data.operation,
										serviceId = args.row.data.id,
										showOrHide = false;;

									// var cb = $("<div class='date-text pos'><span class='service_set_img'><span></div>");
									var cb = $("<div class='date-text pos'><button class='btn btn-primary'>设置</button></div>");
									var setBox = $("<div class='service_set_box'><span class='Lua'>Lua<i class='triangle-up'></i></span><span class='SSL'>SSL</span><span class='L7'>L7协议</span><span class='sample'>设置阈值</span><span class='care'>取消关注</span></div>");
									setBox.appendTo(cb);
									cb.click(function() {
										if (showOrHide) {
											$current = $(this).find(".service_set_box");
											$current.parents('table').find(".service_set_box").hide();
											showOrHide = false
											return;
										}
										$current = $(this).find(".service_set_box");
										$current.parents('table').find(".service_set_box").hide();
										$current.show();
										showOrHide = true;
										return false;
									});

									cb.find(".service_set_box .Lua").click(function() {
										//设置LUA
										ctrl.topoMenuHandler_CONFIG_LUA(serviceId);
										ctrl.set("currentServiceId", serviceId);
										ctrl.set("setupGroupLua", false);
										ctrl.set('dialogAction', "setLua")
										cb.parents('table').find(".service_set_box").hide();
										showOrHide = false
										return false;
									});
									cb.find(".service_set_box .SSL").click(function() {
										var data = args.row.data;
										//设置SSL
										ctrl.topoMenuHandler_CONFIG_SSL(serviceId, data);
										ctrl.set('dialogAction', "setNodeSsl");
										ctrl.set("currentServiceId", serviceId);
										cb.parents('table').find(".service_set_box").hide();
										showOrHide = false
										return false;
									});
									cb.find(".service_set_box .L7").click(function() {
										//配置L7模块
										var data = args.row.data;
										ctrl.topoMenuHandler_CONFIG_L7(data);
										ctrl.set('dialogAction', "setNodeL7")

									});
									cb.find(".service_set_box .sample").click(function() {
										//设置阈值
										var data = args.row.data;
										var configThresholdsView = Broada.getView("businessConfigThresholdView");
										configThresholdsView.set("targetResource", {
											targetId: serviceId,
											targetName: data.name
										});
										configThresholdsView.requireThreshold(serviceId);
										configThresholdsView.openDialog();

										cb.parents('table').find(".service_set_box").hide();
										showOrHide = false
										return false;
									});
									cb.find(".service_set_box .care").click(function() {
										//取消关注
										var data = args.row.data;
										confirmDialog("是否取消关注" + data.name + ",并删除该节点的配置信息？")
											.then(function() {
												cb.parents('table').find(".service_set_box").hide();
												showOrHide = false;
												ctrl.focusRequest(serviceId, {
														"focus": 0
													})
													.then(function(response) {
														ctrl.followResponse();
														ctrl.serviceFocusCountRequest();
													});
												ctrl.followResponse();
											});


										return false;
									});

									cb.appendTo(args.$container);
									return true;
								}
							}
						});
					}
				};

				if (!this.get("auth.isAdmin")) {
					columns.shift();
				}

				return columns;
			}),

			serviceNodeGroup: [],

			//数组去重

			arrayToWeight: function(arr) {
				var res = [];
				var json = {};
				for (var i = 0; i < arr.length; i++) {
					if (!json[arr[i]]) {
						res.push(arr[i]);
						json[arr[i]] = 1;
					}
				}
				return res;
			},

			//删除数组指定一项

			findIndex: function(arr, val) {
				for (var i = 0; i < arr.length; i++) {
					if (arr[i] == val) return i;
				}
				return -1;
			},

			removeArrayItem: function(arr, val) {
				var index = this.findIndex(arr, val);
				if (index > -1) {
					arr.splice(index, 1);
				}
				return arr;
			},

			bindNetworkCheckedToCheckbox: function() {

				var data = this,
					cb = data._$checkbox,
					serviceNodeGroup = data.ctrl.get("serviceNodeGroup");
				var checked = Ember.get(data, "_checked");
				cb.prop("checked", checked);

				serviceNodeGroup.push(data.id);
				serviceNodeGroup = data.ctrl.arrayToWeight(serviceNodeGroup);
				if (data._checked) {

				} else {
					serviceNodeGroup = data.ctrl.removeArrayItem(serviceNodeGroup, data.id);
				}
				data.ctrl.set("serviceNodeGroup", serviceNodeGroup);


				// data.ctrl.clrSelectChange(data, checked);
			},

			networkCheckboxClick: function(e) {
				e.stopPropagation();

				var cb = $(this);
				var model = cb.data("model");
				var checked = cb.prop("checked");
				cb.prop("checked", checked);
				Ember.set(model, "_checked", checked);
			},

			/*
				获取L7层协议下拉数据
			*/
			getL7OptionData: function(refresh) {
				var me = this;
				return this.store.ajax("GET", "protocols/L7").then(function(response) {
					if (response.protocols) {
						var arr = [{
							displaytext: '请选择',
							value: ''
						}];
						Ember.EnumerableUtils.forEach(response.protocols, function(item) {
							arr.push({
								displaytext: item.name,
								value: item.l7_proto,
								data: item
							})
						});
						me.set("l7Options", Ember.A(arr));
					}
				});
			},

			/*
				菜单按钮处理函数 配置L7层服务
			*/
			topoMenuHandler_CONFIG_L7: function(data, topoView) {
				var ctrl = this;
				var dialog = Broada.getView("businessDetailGaugeSetL7"),
					form = {
						id: data.id,
						protocol: data.protocol || data.autoDiscoveryProtocol || ''
					},
					promise = this.getL7OptionData();
				if (promise) {
					promise.then(function() {
						ctrl.set('nodeForm', form);
					});
				} else {
					this.set('nodeForm', form);
				};

				dialog.set('nodeModel', data);
				this.set("nodeAddformTip", "");
				dialog.openDialog();
			},

			serviceFocusCountRequest: function() {
				var ctrl = this;
				return this.store.ajax("GET", "nodes/serviceFocusCount")
					.then(function(response) {
						var serviceFocusCount = response.serviceFocusCount;
						ctrl.set("serviceFocus", serviceFocusCount.serviceFocus);
						ctrl.set("serviceAll", serviceFocusCount.serviceAll);
						return serviceFocusCount;
					});

			},

			focusRequest: function(serviceId, params) {
				return this.store.ajax("PUT", "nodes/" + serviceId + "/service/focus", params);
			},

			alerts: Ember.A(),

			followResponse: function() {
				var ctrl = this;
				var params = {
					focus: "1",
					ip: this.get("serviceIP"),
					serverity: this.get("serverity"),
					pageIndex: this.get("pageIndex"),
					pageSize: this.get("pageSize"),
					port: this.get("portNum"),
					startDate: +this.get("startDate"),
					endDate: +this.get("endDate"),
					serviceType: this.get("serviceValue"),
					"orderBy": this.get("orderBy"),
					"desc": this.get("desc")
				};

				if (isLocalDebugModel) {
					params = {
						"focus": "1"
					};
				}
				return this.store.ajax("GET", "nodes/service", params)
					.then(function(response) {
						var nodes = Ember.A(response.nodes),
							receive = "network/bytes/rx",
							responseTime = "system/response_time/avg",
							session = "network/connection/total",
							throughput = "system/throughput/total",
							errorNum = "system/error/count",
							send = "network/bytes/tx",
							serverName = ctrl.get("serverName");

						nodes.forEach(function(node, index) {
							if (!node.performance) {
								return;
							}
							node.timestamp = node.performance.timestamp;
							node.receive = node.performance[receive];
							node.response = node.performance[responseTime];
							node.session = node.performance[session];
							node.throughput = node.performance[throughput];
							node.send = node.performance[send];
							node.errorNum = node.performance[errorNum];
						});
						if (nodes.length == 0) {
							ctrl.set("isAdd", true)
							ctrl.set("pageIndex", 0);
							ctrl.set("pageSize", 10);
							ctrl.set("totalRows", 0);
						} else {
							ctrl.set("isAdd", false)
							ctrl.set("pageIndex", response.meta.pageIndex);
							ctrl.set("pageSize", response.meta.pageSize);
							ctrl.set("totalRows", response.meta.total);
						}
						ctrl.set("alerts", Ember.A(nodes));
					})
			},
			serviceCountRequest: function() {
				return this.store.ajax("GET", "alarms/serviceCount");
			},
			topoMenuHandler_CONFIG_SSL: function(serviceId, data) {
				var ctrl = this;
				var dialog = Broada.getView("businessNodeSsl");
				dialog.openDialog();
				this.set("nodeSslformTip", "");
				this.set('nodeForm', {
					ssltype: data.ssltype,
					sslpwd: data.sslpwd
				});

				this.store.ajax("GET", "nodes/ssl", {
						serviceId: serviceId
					})
					.then(function(response) {
						ctrl.set("hasNodeSSL", !!response.result);
						dialog.openDialog();
					});
			},

			topoMenuHandler_CONFIG_LUA: function(servieceId) {
				var ctrl = this;
				var dialog = Broada.getView("businessNodeLua");

				ctrl.set("nodeLuaformTip", null);

				dialog.openDialog();

				this.store.ajax("GET", "nodes/lua", {
						serviceId: servieceId
					})
					.then(function(response) {
						ctrl.set('nodeForm', {
							lua: response.result.lua
						});
					});
			},

			actions: {

				/*
					设置L7协议
				*/
				setNodeL7: function(dialog) {
					var protocolName = this.get("selectObject") ? this.get("selectObject").displaytext : '';
					var form = this.get('nodeForm'),
						nodeModel = dialog.get('nodeModel');

					if (form.protocol == '') return this.set("nodeAddformTip", "请选择L7服务！");

					this.store.ajax("PUT", "nodes/protocol", {
						service_id: form.id,
						l7_proto: form.protocol
					}).then(function(response) {
						alertTip("保存成功！", "info");
						Ember.set(nodeModel, 'protocol', form.protocol);
						Ember.set(nodeModel, 'protocolName', protocolName);
						if (response && response.node) {
							Ember.set(nodeModel, 'iconUrl', response.node.iconUrl);
						}
						dialog.closeDialog();
					});
				},
				setupGroupLua: function() {
					var ctrl = this,
						serviceNodeGroup = ctrl.get("serviceNodeGroup");

					var dialog = Broada.getView("businessNodeLua");

					ctrl.set("nodeLuaformTip", null);

					ctrl.set("setupGroupLua", true);

					ctrl.set('nodeForm', {
						lua: ""
					});
					if(serviceNodeGroup.length){
						dialog.openDialog();
					}else{
						alertTip("请勾选服务节点！", "info");
					}
				},
				pageIndexChanged: function(e, data, view) {
					var pageNo = data.newPageIndex;
					this.set("pageIndex", pageNo);

					this.followResponse();
				},
				search: function() {
					var serviceIP = this.get("serviceIP"),
						port = this.get("portNum");
					if (serviceIP) {
						var reg1 = /^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]))|(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])|((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]))|((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]))$/;
						if (!reg1.test(serviceIP)) {
							alert("对不起，您输入的查询IP地址有误，请重新输入!");
							return false;
						}

					}
					if (port) {
						var re = /^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/;
						if (!re.test(port)) {
							alert("对不起，您输入的端口有误，请重新输入!");
							return false;
						}
					}

					this.followResponse();
				},
				gridSorted: function(e, data, view) {
					view.ensureControl(false);
					var dataKey = data.column.dataKey;
					switch (dataKey) {
						case "response":
							dataKey = "system/response_time/avg";
							break;
						case "error":
							dataKey = "system/error/count";
							break;
						case "throughput":
							dataKey = "system/throughput/total";
							break;
						case "successRate":
							dataKey = "system/success/rate";
							break;
					}
					this.set("orderBy", dataKey);
					var sortKey = data.sortCommand;
					this.set("desc", data.sortDirection == "descending" || undefined);
					this.followResponse()
						.then(function(response) {
							view.ensureControl(true);
						});
				},

				addService: function() {
					this.transitionToRoute("service.server.allserver");
				},
				itemClickAlarts: function(serverity) {
					var ctrl = this;
					ctrl.set("serverity", serverity);
					ctrl.set("pageIndex", 0);
					ctrl.followResponse();
				},
				timeRangesChange: function(timeRange) {
					$(".wijmo-wijgrid").css("overflow", "visible");
					var ctrl = this;
					ctrl.set("startDate", timeRange.startDate);
					ctrl.set("endDate", timeRange.endDate);

					ctrl.set("pageIndex", 0);
					$(".wijmo-wijgrid").css("overflow", "visible");
					ctrl.getserviceType();

					ctrl.followResponse();

					ctrl.serviceCountRequest()
						.then(function(response) {
							var serRankNums = Ember.A(response.serRankNums);
							serRankNums.forEach(function(node) {
								switch (node.alarmType) {
									case "严重":
										node.id = "serious";
										break
									case "警告":
										node.id = "alerts";
										break
									case "提醒":
										node.id = "remind";
										break

								}
							});
							ctrl.set("serRankNums", serRankNums);
						});
				}

			}
		});

		/*
			设置服务名
		 */
		Controller.reopen({
			actions: {
				/*
					设置服务名
				*/
				setNodeName: function(serviceId) {
					var ctrl = this,
						serverName = ctrl.get("serviceInputName"),
						dialog = Broada.getView("serviceAllServer"),
						currentServiceObject = ctrl.get("currentServiceObject"),
						currentServiceId = ctrl.get("currentServiceId");
					currentServiceObject["name"] = serverName;
					if (!serverName) {
						return this.set("serviceNameformTip", "服务名不能为空");
					}

					if (serverName.length > 20) {
						return this.set("serviceNameformTip", "服务名不能超过20个");
					}
					ctrl.modifyNnameRequest(currentServiceId, currentServiceObject);
					ctrl.followResponse();
					dialog.closeDialog();
				}
			}
		});

		/*
			设置LUA功能扩展
		*/
		Controller.reopen({
			actions: {
				/*
					设置LUA
				*/
				setLua: function(serviceId) {
					var ctrl = this,
						dialog = Broada.getView("businessNodeLua"),
						formData = this.get('nodeForm'),
						currentServiceId = ctrl.get("currentServiceId"),
						setupGroupLua = ctrl.get("setupGroupLua");

					if (setupGroupLua) {
						currentServiceId = JSON.stringify(ctrl.get("serviceNodeGroup"));
						ctrl.set("setupGroupLua", false);
					}

					this.store.ajax("PUT", "nodes/lua", {
							serviceId: currentServiceId,
							lua: formData.lua
						})
						.then(function(response) {
							if (response.status == "invalid") {
								ctrl.set("nodeLuaformTip", response.message);
								setTimeout(function() {
									var alert_height = $('#businessNodeLua').find('.alert').height();
									$('#businessNodeLua').find('textarea').height(370 - alert_height)
								}, 1)
							} else {
								alertTip("保存成功！", "success");
								dialog.closeDialog();
							}
						});
				}
			}
		});

		/*
			设置节点SSL证书功能扩展
		*/
		Controller.reopen({
			sslTypes: Ember.A([{
				displaytext: "RSA证书",
				value: "RSA"
			}]),

			actions: {
				/*
					设定SSL证书
				*/
				setNodeSsl: function(dialog) {
					var $form = $("#businessNodeSslForm"),
						formData = this.get('nodeForm'),
						nodeModel = dialog.get('nodeModel'),
						isBlank = Ember.isBlank,
						currentServiceId = this.get("currentServiceId");

					/*if (isBlank(formData.ssltype)){
						return this.set("nodeSslformTip", "证书类型不能为空");
					}*/

					if (!formData.privateKeyFile) {
						alertTip("请选择文件！");
						return;
					}

					var formUploader = new FormUploader($form[0], {
						action: ADAPTER_URL + "/nodes/ssl",
						params: {
							serviceId: currentServiceId,
							sslType: formData.ssltype || 'RSA',
							sslPwd: formData.sslpwd,
							token: $.cookie("token")
						}
					});
					formUploader.submit()
						.then(function(response) {
							dialog.closeDialog();
						})
				},

				/*
					删除已设定的SSL证书
				*/
				deleteNodeSsl: function() {
					var ctrl = this,
						dialog = Broada.getView("businessNodeSsl");
					this.store.ajax("DELETE", "nodes/ssl", {
							serviceId: this.get("currentServiceId")
						})
						.then(function() {
							alertTip("证书已删除");
							dialog.closeDialog();
							// ctrl.set("nodeSslformTip", "证书已删除");
						});

				},

				resetNodeSsl: function() {
					this.set("hasNodeSSL", false);
				}
			}
		});

		APM.ServiceServerFollowController = Controller;

		return Controller;
	}
);